import { createDateText, createDocsText, toggleAlphaTween } from '../utils/index';
import writing from '../utils/text';

export default class ConfirmScene {
  static scene: Phaser.Scene;

  static home_arrows: Phaser.GameObjects.Image;

  static icon_hand: Phaser.GameObjects.Image;

  static header_text: Phaser.GameObjects.Container;

  static text: Phaser.GameObjects.Text;

  static g1_light: Phaser.GameObjects.Image;

  static g1_luohu: Phaser.GameObjects.Image;

  static isDoubleTouch = false;

  static init(_this: Phaser.Scene) {
    this.scene = _this;

    const group = _this.add.group();
    // this.bg = createHomeBg(_this);
    this.header_text = this.createText(_this).setDepth(106);
    this.home_arrows = _this.add.image(352, _this.cameras.main.height - 300, 'image-home_arrows').setDepth(107);
    this.icon_hand = _this.add.image(396, this.home_arrows.y + 50, 'image-icon_hand').setDepth(108);

    this.text = _this.add.text(0, 0, '-双指放大，聚焦罗湖-', { fill: '#000', font: 'bold 35px Arial' });
    this.text.setX(_this.cameras.main.centerX);
    this.text.setY(this.icon_hand.y + 100);
    this.text.setOrigin(0.5, 0);
    this.text.setDepth(108);

    group.addMultiple([this.header_text, this.home_arrows, this.icon_hand, this.text]);
    group.setAlpha(0);

    toggleAlphaTween({ scene: _this, targets: group.getChildren(), alpha: 1 });

    _this.tweens.add({
      targets: [this.home_arrows, this.icon_hand],
      duration: 800,
      repeat: -1,
      yoyo: true,
      props: { scale: 1.2 },
    });
  }

  static create(_this: Phaser.Scene) {
    const { centerX, centerY } = _this.cameras.main;

    this.g1_luohu = _this.add.image(centerX - 28, centerY + 117, 'image-g1_luohu').setDepth(110);

    this.g1_light = _this.add.image(this.g1_luohu.x, this.g1_luohu.y, 'image-g1_light').setDepth(109);
    this.g1_light.setAlpha(0);
  }

  static next() {
    toggleAlphaTween({
      scene: ConfirmScene.scene,
      targets: [this.home_arrows, this.header_text, this.text, this.icon_hand, this.g1_light, this.g1_luohu],
      alpha: 0,
      onComplete: () => {
        this.home_arrows.destroy();
        this.header_text.destroy();
        this.text.destroy();
        this.icon_hand.destroy();
        this.g1_light.destroy();
        this.g1_luohu.destroy();
      },
    });
  }

  static createText(_this: Phaser.Scene) {
    const text = _this.add.container();
    const home_text1 = _this.add.container();
    const home_title1 = createDateText(_this, {
      x: 30,
      y: 30,
      text: writing.screen_1.date,
    });
    const home_docs1 = createDocsText(_this, {
      x: 30,
      y: home_title1.y + home_title1.height * 1.2,
      text: writing.screen_1.docs,
    });

    const home_text2 = _this.add.container();
    const home_title2 = createDateText(_this, {
      x: 30,
      y: 30 + home_docs1.y + home_docs1.height,
      text: writing.screen_1_1.date,
    });
    const home_docs2 = createDocsText(_this, {
      x: 30,
      y: home_title2.y + home_title2.height * 1.2,
      text: writing.screen_1_1.docs,
    });

    home_text1.add([home_title1, home_docs1]);
    home_text2.add([home_title2, home_docs2]);

    text.add([home_text1, home_text2]);

    return text;
  }
}
